// --no-module-wrap--
var run = function (combine) {
    describe('loader should report error ' + (combine ? 'at combo mode' : ''), function () {
        var S = KISSY;

        beforeEach(function () {
            KISSY.config('combine', !!combine);
        });

        afterEach(function () {
            KISSY.clearLoader();
        });

        it('should works', function () {
            KISSY.config({
                'packages': {
                    'report': {
                        base: '/kissy/src/loader/tests/specs/error-report/' +
                            (combine ? 'combo' : 'simple')
                    }
                }
            });

            if (combine) {
                KISSY.config('modules', {
                    'report/s1': {
                        requires: ['./s2']
                    },
                    'report/s3': {
                        requires: ['./s4', './s2']
                    }
                });
            }

            var success1;
            var error1;

            KISSY.use('report/s1', {
                success: function () {
                    success1 = arguments;
                },
                error: function () {
                    error1 = arguments;
                }
            });

            var success2;
            var error2;


            KISSY.use('report/s3', {
                success: function () {
                    success2 = arguments;
                },
                error: function () {
                    error2 = arguments;
                }
            });

            waitsFor(function () {
                return (success1 || error1) && (success2 || error2);
            });

            runs(function () {
                expect(success1[1]).toBe('!!');
                expect(success1.length).toBe(2);
                expect(error1).toBeUndefined();
                expect(success2).toBeUndefined();
                expect(error2.length).toBe(combine ? 2 : 1);
                expect(error2[0].name).toBe(combine ? 'report/s3' : 'report/s4');
                expect(error2[0].status).toBe(S.Loader.Status.ERROR);
                if (combine) {
                    expect(error2[1].name).toBe('report/s4');
                    expect(error2[1].status).toBe(S.Loader.Status.ERROR);
                }
            });

        });
    });
};

run();
run(1);